﻿using UnityEngine;
using System.Collections;

public class Offense : MonoBehaviour {

	public bool hasFlag = false;

    private Vector3 startPosition;
    private Quaternion startRotation;
	// Use this for initialization
	void Start () {
        startPosition = transform.position;
        startRotation = transform.rotation;
    }

    void OnCollisionEnter(Collision other) {
        Debug.Log("OnCollisionEnter");

        if (other.gameObject.tag == "Defense")
        {
            if (hasFlag)
            {
                CTFGameManager.Instance.DropFlag();

                //旗子在手，则将旗子撤下(旗子在第一个)
                if (transform.childCount > 0) {
                    Transform flagTrans = transform.GetChild(0);//得到旗帜
                    flagTrans.GetComponent<Flag>().owner = null;
                    flagTrans.parent = null;

                    //守护方接手旗子
                }

                //
                hasFlag = false;

            }
			transform.position = startPosition;
            transform.rotation = startRotation;
        }

    }
	// Update is called once per frame
	void Update () {
	
	}
}
